use std::rc::Rc;
use std::time::Instant;

use raytracing::{global::MaterialType, scene::Scene, sphere::Sphere, v3f, vector::{Vector3f, Vector2f}, v2f, triangle::MeshTriangle, light::Light, renderer::Renderer};

fn main() {
    let start = Instant::now();

    let scene = Scene::new(1280, 960);
    let mut sph1 = Sphere::new(v3f!(-1., 0., -12.), 2.);
    sph1.obj_attr.material_type = MaterialType::DiffuseAndGlossy;
    // sph1.obj_attr.material_type = MaterialType::Reflection;
    // sph1.obj_attr.material_type = MaterialType::ReflectionAndRefraction;
    sph1.obj_attr.diffuse_color = v3f!(0.2, 0.7, 0.8);


    let mut sph2 = Sphere::new(v3f!(0.5, -0.5, -8.), 1.5);
    sph2.obj_attr.ior = 1.5;
    // sph2.obj_attr.material_type = MaterialType::DiffuseAndGlossy;
    sph2.obj_attr.material_type = MaterialType::ReflectionAndRefraction;

    scene.add_object(Rc::new(sph1));
    scene.add_object(Rc::new(sph2));

    let verts = vec![
        v3f!(-5., -3., -6.),
        v3f!(5., -3., -6.),
        v3f!(5., -3., -16.),
        v3f!(-5., -3., -16.),
    ];

    let vert_index: Vec<usize> = vec![0, 1, 3, 1, 2, 3];
    let st = vec![v2f!(), v2f!(1., 0.), v2f!(1., 1.), v2f!(0., 1.)];

    let mut mesh = MeshTriangle::new(verts, vert_index, 2, st);
    mesh.obj_attr.material_type = MaterialType::DiffuseAndGlossy;
    // mesh.obj_attr.material_type = MaterialType::ReflectionAndRefraction;

    scene.add_object(Rc::new(mesh));

    scene.add_light(Rc::new(Light::new(v3f!(-20., 70., 20.) , v3f!(0.5))));
    scene.add_light(Rc::new(Light::new(v3f!(30., 50., -12.) , v3f!(0.5))));

    let r = Renderer::new(scene);
    r.render();

    println!("time cost : {} us.", start.elapsed().as_micros());
}
